//
//  SlidesTableViewCell.m
//  GoShops
//
//  Created by zcj on 15-12-4.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//

#import "SlidesTableViewCell.h"
#import "MediaListModel.h"
#import "HorizontailCell.h"
#import "Grouble.h"

@interface SlidesTableViewCell()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic,weak)UILabel * titleLabel;
@property (nonatomic,weak)UIImageView * imageViews;
@property (nonatomic,weak)UICollectionView * collectionView;
@property (nonatomic,strong)NSMutableArray * myArray;
@end
@implementation SlidesTableViewCell

- (NSMutableArray *)myArray
{
    if (_myArray == nil) {
        _myArray = [NSMutableArray array];
    }
    return _myArray;
}
+ (instancetype)SlidesTableViewCell:(UITableView *)tableView
{
    static NSString *ID = @"slidegun";
    SlidesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[SlidesTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    // 设置不能选中,选中每反应
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        CGFloat space=(self.bounds.size.width-4*10)/3;
        
        UIImage * myImg = [UIImage imageNamed:@"icon_mine_level1user"];
        UIImageView * myImageView = [[UIImageView alloc]initWithImage:myImg];
        [self addSubview:myImageView];
        self.imageViews = myImageView;
        
        UILabel * myLable = [[UILabel alloc]initWithFrame:CGRectMake(myImg.size.width + 10, 5, 80, 25)];
        [self addSubview:myLable];
        myLable.textColor=[UIColor blackColor];
        myLable.font=[UIFont systemFontOfSize:18];
        myLable.text = @"Hot";
        self.titleLabel = myLable;
        
        UICollectionViewFlowLayout * layout=[[UICollectionViewFlowLayout alloc] init];
        layout.itemSize=CGSizeMake(space, space+40);
        layout.scrollDirection=UICollectionViewScrollDirectionHorizontal;
        layout.sectionInset=UIEdgeInsetsMake(0, 10, 0, 10);
        UICollectionView *collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 40,self.bounds.size.width, space+40) collectionViewLayout:layout];
        collectionView.delegate=self;
        collectionView.dataSource=self;
        collectionView.showsHorizontalScrollIndicator = NO;
        [collectionView registerClass:[HorizontailCell class] forCellWithReuseIdentifier:@"HorizontailCell"];
        
        collectionView.backgroundColor=[UIColor clearColor];
        [self addSubview:collectionView];
        
        self.collectionView = collectionView;
        

        // Initialization code
    }
    return self;
}
- (void)setMediaModel:(MediaListModel *)mediaModel
{
    _mediaModel = mediaModel;
    NSLog(@"%@",mediaModel.title);
    
    [self.myArray addObject:mediaModel];
    [self.collectionView reloadData];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.myArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HorizontailCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"HorizontailCell" forIndexPath:indexPath];
    
    MediaListModel * model=self.myArray[indexPath.row];
    [cell showDataWith:model];
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    ZCJLog(@"dfjdklfjdklf");
}
- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
